﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Monocle.DataModel;

namespace Monocle.Models
{
    public class PageViewModel
    {
        private tPage _dto;
        public PageViewModel(tPage dto)
        {
            _dto = dto;
        }

        public PageViewModel()
        {
            _dto = new tPage();
        }


        public PageItemCollectionViewModel PageItemList { get; set; }


        [HiddenInput(DisplayValue = false)]
        public Guid ID
        {
            get { return _dto.PK_tPage; }
            set { _dto.PK_tPage = value; }
        }

        [ScriptIgnore]
        [HiddenInput(DisplayValue = false)]
        public byte[] Version
        {
            get { return _dto.Version; }
            set { _dto.Version = value; }

        }

        [Required(ErrorMessageResourceName = "Generic_Required", ErrorMessageResourceType = typeof(Resources.Monocle))]
        [Display(Name = "PageViewModel_Name", ResourceType = typeof(Resources.Monocle))]
        public String Name
        {
            get { return _dto.Name; }
            set { _dto.Name = value; }
        }

        [Display(Name = "PageViewModel_IconName", ResourceType = typeof(Resources.Monocle))]
        public String IconName
        {
            get { return _dto.IconName; }
            set { _dto.IconName = value; }
        }

        [ScriptIgnore]
        [HiddenInput(DisplayValue = false)]
        public Guid FK_tApp
        {
            get { return _dto.FK_tApp; }
            set { _dto.FK_tApp = value; }
        }

        [ScriptIgnore]
        [Display(Name = "PageViewModel_Published", ResourceType = typeof(Resources.Monocle))]
        public bool Published
        {
            get { return _dto.Published; }
            set { _dto.Published = value; }
        }

        [HiddenInput(DisplayValue = false)]
        public String PageItemOrder { get; set; }

        /// <summary>
        /// Returns the DTO
        /// </summary>
        /// <returns></returns>
        public tPage ToDTO()
        {
            return _dto;
        }

        public void UpdateFromDTO(tPage dto)
        {
            _dto = dto;
        }
    }
}